import { isObject } from '../share/index'
import { shapeFlags } from '../share/shapeFlag'

export const Fragment = Symbol('fragment')
export const Text = Symbol('text')

export function createVnode (type, props?, children?) {
  const vnode = {
    type,
    props,
    children,
    el: null,
    shapeFlag: setShapeFlag(type)
  }
  if(typeof children === 'string') {
    vnode.shapeFlag |= shapeFlags.TEXT_CHILDREN
  } else {
    vnode.shapeFlag |= shapeFlags.ARRAY_CHILDREN
  }
  if(vnode.shapeFlag & shapeFlags.STATEFUL_COMPONENT && isObject(children)) {
    vnode.shapeFlag |= shapeFlags.SLOT_CHILDREN
  }
  return vnode
}

function setShapeFlag(type) {
  return typeof type === 'string' ? shapeFlags.ELEMENT : shapeFlags.STATEFUL_COMPONENT
}

export function createTextVnode(text) {
  return createVnode(Text, {}, text)
}